package editor.menu;

import java.awt.Color;
import java.awt.Graphics;

import applet.Screen;

/** A container of buttons and jump lists. */
public class Menu {
	/** */
	public static final int Y = Screen.HEIGHT - Button.HEIGHT;

	/** */
	private static final int NUM_BUTTONS = 6;
	/** */
	private Button[] buttons;
	/** */
	private JumpList jumpList;

	/** */
	public Menu() {
		buttons = new Button[NUM_BUTTONS];
		jumpList = null;
	}

	/**
	 * @param button
	 *            - the button to set it to.
	 */
	public final void addButton(final Button button) {
		buttons[button.getIndex()] = button;
	}

	/**
	 * @param index
	 *            - the position of the button.
	 * @return the button at the given position.
	 */
	public final Button getButton(final int index) {
		if (index < NUM_BUTTONS) {
			return buttons[index];
		} else {
			return null;
		}
	}

	/**
	 * @param newJumpList
	 *            - the list to select.
	 */
	public final void setJumpList(final JumpList newJumpList) {
		jumpList = newJumpList;
	}

	/** @return the visible jump list or null. */
	public final JumpList getJumpList() {
		return jumpList;
	}

	/**
	 * @param g
	 *            - the graphics context to draw to.
	 */
	public final void draw(final Graphics g) {
		// Fill area of screen with black
		g.setColor(Color.BLACK);
		g.fillRect(0, Screen.HEIGHT - Button.HEIGHT, Screen.WIDTH,
				Button.HEIGHT);

		// Draw all the buttons
		for (Button button : buttons) {
			if (button != null) {
				button.draw(g);
			}
		}

		// Draw the jump list
		if (jumpList != null) {
			jumpList.draw(g);
		}
	}

	/** */
	public final void resetButtons() {
		for (Button button : buttons) {
			if (button != null) {
				button.setState(Button.State.NORMAL);
			}
		}
	}
}
